home *** CD-ROM | disk | FTP | other *** search
- unit fmMain;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Save: TButton;
- Restore: TButton;
- Button1: TButton;
- ColorDialog1: TColorDialog;
- Button2: TButton;
- ItemNames: TListBox;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure SaveClick(Sender: TObject);
- procedure RestoreClick(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private declarations }
- hDeskWin: hWnd;
- dmResponse: Integer;
- dmData: PChar;
- procedure WMCopyData (var Message: TWMCopyData); message wm_CopyData;
- function PendOnDeskTopMessage (Msg, wParam, lParam: Integer): PChar;
- procedure SetTextColor (Value: LongInt);
- function GetTextColor: LongInt;
- function GetItemCount: Integer;
- function GetItemCaption (Index: Integer): String;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses CommCtrl, DeskManMessages;
-
- function DeskManagerLoad (AppWindow: hWnd): Bool; stdcall; external 'DeskManager.dll';
- function DeskManagerUnload: Bool; stdcall; external 'DeskManager.dll';
- function DeskManagerListView: HWnd; stdcall; external 'DeskManager.dll';
- function DeskManagerShellThread: DWord; stdcall; external 'DeskManager.dll';
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- Msg: TMsg;
- begin
- DeskManagerLoad (Handle);
- GetMessage (Msg, 0, 0, 0);
- hDeskWin := FindWindow (Nil, 'Delphi Desktop 2001');
- if hDeskWin = 0 then raise Exception.Create ('Trouble at ''mill');
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- SendMessage (hDeskWin, wm_Close, 0, 0);
- while IsWindow (hDeskWin) do Application.ProcessMessages;
- DeskManagerUnload;
- end;
-
- function TForm1.GetItemCount: Integer;
- begin
- Result := ListView_GetItemCount (DeskManagerListView);
- end;
-
- function TForm1.GetTextColor: LongInt;
- begin
- Result := SendMessage (hDeskWin, DM_GetTextColor, 0, 0);
- end;
-
- procedure TForm1.SetTextColor (Value: LongInt);
- begin
- if GetTextColor <> Value then SendMessage (hDeskWin, DM_SetTextColor, 0, Value);
- end;
-
- procedure TForm1.WMCopyData (var Message: TWMCopyData);
- begin
- // Make sure it's from the desktop manager DLL
- if Message.From = hDeskWin then with Message, Message.CopyDataStruct^ do begin
- ReallocMem (dmData, cbData);
- Move (lpData^, dmData^, cbData);
- dmResponse := dwData;
- Result := Integer (True);
- end;
- end;
-
- function TForm1.PendOnDeskTopMessage (Msg, wParam, lParam: Integer): PChar;
- begin
- dmResponse := -1;
- PostMessage (hDeskWin, Msg, wParam, lParam);
- while dmResponse <> Msg do Application.ProcessMessages;
- Result := dmData;
- end;
-
- function TForm1.GetItemCaption (Index: Integer): String;
- begin
- Result := '';
- if (Index >= 0) and (Index < GetItemCount) then
- Result := StrPas (PendOnDesktopMessage (DM_GetItemText, Index, 0));
- end;
-
- procedure TForm1.SaveClick(Sender: TObject);
- begin
- //SendMessage (hDeskWin, wm_App, 0, 1);
- end;
-
- procedure TForm1.RestoreClick(Sender: TObject);
- begin
- //SendMessage (hDeskWin, wm_App, 0, 0);
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if ColorDialog1.Execute then SetTextColor (ColorDialog1.Color);
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- var
- Idx: Integer;
- begin
- ItemNames.Clear;
- for Idx := 0 to GetItemCount - 1 do
- ItemNames.Items.Add (GetItemCaption (Idx));
- end;
-
- end.
-